<?php
	check_login();
	$a = getAction();

	switch($a) {
		case 'index':
			$sql="select  * from ".table('huifupic') . " where 1=1 ";
            $sql2="select  count(*)  from ".table('huifupic')."  where 1=1 ";
            $url="admin.php?m=huifupic";
            
            $starttime=$_GET['starttime']=htmlspecialchars($_GET['starttime']);
            $endtime=$_GET['endtime']=htmlspecialchars($_GET['endtime1']);
            
            if($starttime && $endtime){
            	$url.="&starttime=$starttime&endtime=$endtime";
                $w.=" AND createtime>'$starttime' AND createtime<'$endtime' ";
			}
                        
            $sql.=$w;
            $sql2.=$w;
                        
            $sql.=" order by id desc ";
            //开始分页
            $rscount=$db->getOne($sql2);
            $pagesize=50;
            $page=max(1,intval($_GET['page']));
            $start=($page-1)*$pagesize;
            $pagelist=multipage($rscount,$pagesize,$page,$url);	
            $sql.=" limit $start,$pagesize";
            $smarty->assign("pagelist",$pagelist);
            $smarty->assign("page",$page);
                        
            $res2=$db->query($sql);
            while($rs2=$db->fetch_array($res2)) {
            	if($rs2['wximageurl']==""){
                	$rs2['wximageurl']=$rs2['picurl'];
                }
                
                $rs2["username"] = $db->getOne("select nickname from " . table("user") . " where openid = '" . $rs2["weixinid"] . "'");
                                                
                $huifupic[]=$rs2;
			}

			$smarty->assign("rscount",$rscount);//统计订单总数
            $smarty->assign("huifupic",$huifupic);
			$smarty->display("huifupic.html");
			break;
		case 'del':
			$id=intval($_GET['id']);
			$picData = $db->getRow("select  *  from ".table('huifupic')." where id='$id'");
			if($picData) {
				unlink(ROOT_PATH . $picData["picurl"]);
			}
			$db->query("DELETE FROM ".table('huifupic')." WHERE id='$id' ");
			header("location:admin.php?m=huifupic&page=" . $_GET["page"]);
			break;
}
?>